﻿namespace Hidistro.UI.AccountCenter.CodeBehind
{
    using ASPNET.WebControls;
    using Hidistro.Core;
    using Hidistro.Core.Entities;
    using Hidistro.Core.Enums;
    using Hidistro.Entities.Orders;
    using Hidistro.Entities.Sales;
    using Hidistro.Membership.Context;
    using Hidistro.SaleSystem.Member;
    using Hidistro.UI.Common.Controls;
    using Hidistro.UI.SaleSystem.Tags;
    using System;
    using System.Collections.Specialized;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using wnxd.javascript;

    public class UserOrders_new : MemberTemplatedWebControl
    {
        private wnxd_UserOrder orderList;
        private UserOrderManage_OrderList userorderlist;
        private Pager pager;
        private DropDownList dropPayType;
        private HtmlInputHidden hdorderId;
        private IButton btnSearch;
        private TextBox txtKeyWord;
        protected override void AttachChildControls()
        {
            PageTitle.AddSiteNameTitle("我的订单");
            this.userorderlist = (UserOrderManage_OrderList)this.FindControl("UserOrderManage_OrderList");
            this.pager = (Pager)this.FindControl("pager");
            this.dropPayType = (DropDownList)this.FindControl("dropPayType");
            this.hdorderId = (HtmlInputHidden)this.FindControl("hdorderId");

            if (!this.Page.IsPostBack)
            {
                this.dropPayType.DataSource = TradeHelper.GetPaymentModes(PayApplicationType.payOnPC);
                this.dropPayType.DataTextField = "Name";
                this.dropPayType.DataValueField = "ModeId";
                this.dropPayType.DataBind();
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "User/Skin-UserOrders_new.html";
            }
            base.OnInit(e);
        }
       
        protected json btnPay()
        {
            string orderId = this.Page.Request.Form["orderid"];
            int result = 0;
            int.TryParse(this.Page.Request.Form["type"], out result);
            PaymentModeInfo paymentMode = TradeHelper.GetPaymentMode(result);
            if (paymentMode != null)
            {
                OrderInfo orderInfo = TradeHelper.GetOrderInfo(orderId);
                orderInfo.PaymentTypeId = paymentMode.ModeId;
                orderInfo.Gateway = paymentMode.Gateway;
                orderInfo.PaymentType = paymentMode.Name;
                TradeHelper.UpdateOrderPaymentType(orderInfo);
            }
            return new json(new { url = Globals.GetSiteUrls().UrlData.FormatUrl("sendPayment", new object[] { orderId }) });
        }
    }
}

